/*
*	(*^。^*) TFrameWork License (*^。^*)
*/

/*
 *  Title :  
 *          
 *  Description :  
 *          
 *          
 *  Date : 
 *
 *  Author : DengPing
 *
 *  Modify : 
 */

using System;
using UnityEngine;
using Sirenix.OdinInspector;

namespace TFrameWork.Module.ActionEditor
{
    [System.Serializable]
    public abstract class DataBase : SerializedScriptableObject, ICloneable
    {

        public static T New<T>() where T : DataBase, new()
        {
           var newData = ScriptableObject.CreateInstance(typeof(T)) as T;
           newData.name = typeof(T).Name +"_Event";
           return newData;
        }

        public static T New<T>(Type t) where T : DataBase
        {

            var newData = ScriptableObject.CreateInstance(t);

            if (newData is T data)
            {
                data.name = t.Name +"_Event";
                return data;
            }
            ActionEditorLog.Error($"泛型T {typeof(T)} 和参数 t {t} 不匹配");
            return null;
        }

        public virtual object Clone()
        {
            var clone = ScriptableObject.CreateInstance(GetType());
            clone.name = name;
            return clone;
        }
    }
}
